package com.jrx.anytxn.customer.dto.customer.medical;

import com.jrx.anytxn.common.data.TxnRespCode;
import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.uitl.StringUtils;
import com.jrx.anytxn.customer.constant.CustomerConstant;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 信用就医业务，cms客户端发起冻结、解冻操作处理结果返回
 *
 * @author user
 * @date 2022/8/9 14:30
 */
public class CustomerLimitFrozeFrozeReq extends CustomerLimitFrozeBaseReq implements Serializable {
    private static final long serialVersionUID = -7052966390686842121L;

    /**
     * 冻结解冻标识F-冻结，R-解冻
     * 表字段:status
     */
    @ApiModelProperty(value = "冻结解冻标识", example = "F")
    @Length(min = 1, max = 1, message = "结解冻标识F-冻结，R-解冻只能取其一")
    private String operateType;

    /**
     * 冻结额度
     */
    private BigDecimal frozeAmount;

    /**
     * 商户号
     * 表字段:merchantNo
     */
    @ApiModelProperty(value = "商户号", example = "1X1Z22")
    @Size(max = 32, message = "商户号merchantNo长度不能大于32位")
    private String merchantNo;

    /**
     * 调整原因
     */
    @ApiModelProperty(value = "补充信息", example = "挂号冻结")
    @Size(max = 200, message = "补充信息adjustReason长度不能大于200位")
    private String adjustReason;

    /**
     * 冻结流水号
     * 表字段:froze_no
     */
    @ApiModelProperty(value = "冻结流水号", example = "KPIS12354")
    @Size(max = 32, message = "冻结流水号长度不能大于32位")
    private String frozeNo;

    public String getOperateType() {
        return operateType;
    }

    public void setOperateType(String operateType) {
        this.operateType = operateType;
    }

    public BigDecimal getFrozeAmount() {
        return frozeAmount;
    }

    public void setFrozeAmount(BigDecimal frozeAmount) {
        this.frozeAmount = frozeAmount;
    }

    public String getMerchantNo() {
        return merchantNo;
    }

    public void setMerchantNo(String merchantNo) {
        this.merchantNo = merchantNo;
    }

    public String getAdjustReason() {
        return adjustReason;
    }

    public void setAdjustReason(String adjustReason) {
        this.adjustReason = adjustReason;
    }

    public String getFrozeNo() {
        return frozeNo;
    }

    public void setFrozeNo(String frozeNo) {
        this.frozeNo = frozeNo;
    }

    /**
     * 参数逻辑校验
     *
     * @throws TxnBizException
     */
    public void check() throws TxnBizException {

        if (!(CustomerConstant.OPERATE_TYPE_R.equals(this.operateType) ||
                CustomerConstant.OPERATE_TYPE_F.equals(this.operateType))) {
            throw new TxnBizException(TxnRespCode.PARAM_ERROR.getCode(), "冻结处理，冻结解冻标识必须为F或R；（F-冻结，R-解冻）");
        }

        if (CustomerConstant.OPERATE_TYPE_F.equals(this.operateType)) {
            if (StringUtils.isBlank(this.getFrozeNo())) {
                throw new TxnBizException(TxnRespCode.PARAM_ERROR.getCode(), "冻结处理，冻结流水号不能为空");
            }
            if (frozeAmount == null) {
                throw new TxnBizException(TxnRespCode.PARAM_ERROR.getCode(), "冻结处理，冻结金额不能为空");
            }
            frozeAmount = frozeAmount.setScale(2,BigDecimal.ROUND_HALF_UP);
        }
    }
}
